
import hx.entity.*;
import hx.utiks.CardUtils;
import hx.utiks.test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

public class MobileMain {
    public static void main(String[] args) {
        CardUtils cardUtils=new CardUtils();
        String[] cardNumbers=cardNumbers();
        ac:
        while (true){
            System.out.println("======欢迎使用soso移动业务大厅======");
            System.out.println("1.用户登录\t2.用户注册\t3.使用搜搜\t4.话费充值\t5.资费说明\t6.退出系统");
            System.out.print("请选择(1-9)");
            int inuputin=setInput();
            switch (inuputin){
                case 1:{

                    System.out.println("请输入账号");
                    String count=inPutString();
                    System.out.println("请输入密码");
                    String kk=inPutString();
                    try {
                    if (cardUtils.isExistCard(count,kk)){
                        while (true) {
                            System.out.println("======soso移动用户菜单======");
                            System.out.println("1.本月帐单查询套餐\n2.余量查询\n3.打印消费详单\n4.套餐变更办理\n5.办理退网\n请选择输入(1-5)选择功能，其他键返回上一级。");
                            int inuputin2=setInput();
                            switch (inuputin2){
                                case 1:{
                                    System.out.println("您的卡号："+count+"当月账单");
                                    System.out.println("套餐名称："+cardUtils.getCards().get(count).getcTname());
                                    System.out.println("套餐资费："+cardUtils.getCards().get(count).getSerPackage().getPrice());
                                    System.out.println("账户余额："+cardUtils.getCards().get(count).getMoney());
                                    System.out.println("合计："+(cardUtils.getCards().get(count).getMoney()+cardUtils.getCards().get(count).getSerPackage().getPrice()));

                                  cardUtils.getCards().get(count);
                                }
                                continue ;
                                case 2:
                                    System.out.println(count);
                                    cardUtils.showRemainDetail(count);
                                    continue;
                                case 3:
                                    cardUtils.printConsumInfo(count);
                                    continue ;
                                case 4:
                                    System.out.println("1.超人套餐\t2.网虫套餐\t3.话痨套餐");
                                    int tc=setInput();
                                    switch (tc){

                                        case 1:
                                            cardUtils.changingPack(count,"超人套餐");
                                            continue ;
                                        case 2:
                                            cardUtils.changingPack(count,"网虫套餐");
                                            continue ;
                                        case 3:
                                            cardUtils.changingPack(count,"话痨套餐");
                                            continue ;
                                    }
                                    continue ;
                                case 5:
                                    System.out.println("你是否确定办理退网：1确定/2返回");
                                    String ac=inPutString();

                                    if (ac.equals("1")){
                                        cardUtils.delCard(count);
                                        continue ac;
                                    }else continue ;
                                default:
                                    continue ac;
                            }
                        }

                    }else {
                        System.out.println("未找到用户，重新输入或者注册");
                        continue ac;
                    }}catch (NullPointerException a){
                        System.out.println("未找到用户，重新输入或者注册");
                        continue ac;
                    }




                }
                case 2:{
                    MobileCard mobileCard=new MobileCard();
                    int cNumber;
                    int xh;
                    System.out.println("=====可选择的卡号=====");
                    for (int aa=0;aa<cardNumbers.length;aa++){
                        xh=aa+1;
                        System.out.println(xh+"."+cardNumbers[aa]+"\t");
                    }
                    System.out.println("请选择(1-9)");
                    xh=setInput();
                    cNumber= xh - 1;
                    mobileCard.setCardNumber(cardNumbers[cNumber]);
                    System.out.println("请选择套餐");
                    System.out.println("1.话痨套餐 2.超人套餐 3.网虫套餐");
                    System.out.print("请选择套餐(1-3)");
                    xh=setInput();
                    if (xh>=1&&xh<=3){

                        switch (xh){
                            case 1:
                                mobileCard.setSerPackage(new Talkpackage());
                                mobileCard.setcTname("话痨套餐");
                                break;
                            case 2:
                                mobileCard.setSerPackage(new SuperPackage());
                                mobileCard.setcTname("超人套餐");
                                break;
                            case 3:
                                mobileCard.setSerPackage(new NetPackage());
                                mobileCard.setcTname("网虫套餐");
                                break;
                        }

                    }else {
                        System.out.print("错误");
                        break;
                    }
                    System.out.println("请输入名字：");
                    mobileCard.setUserName(inPutString());
                    System.out.println("请输入密码：");
                    mobileCard.setPassWord(inPutString());
                    System.out.println("请输入预存话费：");
                    mobileCard.setRealsSMSCount(Integer.valueOf(inPutString()));
                    if (mobileCard.getRealsSMSCount()< mobileCard.getSerPackage().getPrice()){
                        System.out.println("您预存的话费余额不足以支付本月固定套餐资费，请重新充值:");
                        mobileCard.setRealsSMSCount(Integer.valueOf(inPutString()));
                    }
                    System.out.println("注册成功");
                    System.out.println("卡号："+"\t"+mobileCard.getCardNumber()+"\n"+
                            "用户名："+"\t"+mobileCard.getUserName()+
                            "当前余额："+"\t"+(mobileCard.getRealsSMSCount()-mobileCard.getSerPackage().getPrice()));
                    mobileCard.setMoney(mobileCard.getRealsSMSCount()-mobileCard.getSerPackage().getPrice());
                    mobileCard.getSerPackage().show();
                    cardUtils.addCard(cardNumbers[cNumber],mobileCard);
                    try {
                        cardUtils.savaCards();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                System.out.println("++++++++++++");
                continue ac;
                case 3:{
                    System.out.println("请输入账号");
                    String card=inPutString();
                    cardUtils.useSoso(card);
                }
                continue ac;
                case 4:{

                    System.out.println("请输入充值卡号：");
                    String count=inPutString();
                    System.out.println("请输入充值金额：");
                    double money=inDouble();
                    cardUtils.chargeMoney(count,money);

                }
                continue ac;
                case 5:
                    cardUtils.showDescription();
                    continue ac;
            }
            if (inuputin==6){
                System.out.println("退出系统");
                break;
            }

        }

    }
    private static String  inPutString() {
        Scanner scanner=new Scanner(System.in);
        String sstring=scanner.next();
        return sstring;

    }
    private static double inDouble(){
        Scanner scanner=new Scanner(System.in);
        double a=scanner.nextDouble();
        return a;
    }
    private static int setInput() {
        Scanner scanner = new Scanner(System.in);
       int input=0;
        try {
            input = scanner.nextInt();
            if (input>9||input==0){
                System.out.println("错误输入，重新输入");
                setInput();
            }
        } catch (InputMismatchException e) {
            System.out.println("错误输入，重新输入");
            setInput();
        }


        return input;
    }
    public static   String[] cardNumbers() {
        String numbers[] = new String[9];
        Random random = new Random();
        for (int b = 0; b < 9; b++) {
            String aad = "139";
            for (int a = 0; a < 8; a++) {
                String xz = String.valueOf(random.nextInt(9));
                aad=aad+xz;
            }
            numbers[b] = aad;
        }
        return numbers;
    }
    private void savaCard(){}


}

